using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player_DashState : PlayerStateBase
{
    private float originGravityScale;
    public Player_DashState(Player player, StateMachine stateMachine, string animName) : base(player, stateMachine, animName)
    {

    }
    public override void Enter()
    {
        base.Enter();
        skillManager.skillDash.OnStartEffect();
        //玩家冲刺图片特效
        player.player_VFX.DoImageEffectCo(player.dashDuration);
        originGravityScale = rb.gravityScale;
        rb.gravityScale = 0;
        //设置冲刺时间
        stateTimer = player.dashDuration;
        //将玩家设置为不可攻击
        player.playerHealth.SetCanTakeDamage(false);
        player.gameObject.layer = LayerMask.NameToLayer("NoColliderForPlayer");
    }
    public override void Update()
    {
        base.Update();
        CancelDashState();
        player.SetVelocity(player.dashMoveSpeed * player.dashDir, 0);
        if (stateTimer <= 0)
        {
            if (player.IsGround)
            {
                stateMachine.ChangeState(player.idleState);
            }
            else
            {
                stateMachine.ChangeState(player.jumpFallState);
            }
        }
    }
    public override void Exit()
    {
        base.Exit();
        rb.gravityScale = originGravityScale;
        player.SetVelocity(0, rb.velocity.y);
        //执行玩家冲刺结束时的技能
        skillManager.skillDash.OnEndEffect();
        //将玩家设置为可攻击
        player.playerHealth.SetCanTakeDamage(true);
        player.gameObject.layer = LayerMask.NameToLayer("Player");
    }
    private void CancelDashState()
    {
        if (player.IsWall)
        {
            if (player.IsGround) 
            {
                stateMachine.ChangeState(player.idleState);
            }
            else
            {
                stateMachine.ChangeState(player.wallSildeState);
            }
        }
    }
}
